﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Barbar.UrlGuard.Dal.Persist;
using Barbar.UrlGuard.Dal;

namespace Barbar.UrlGuard.Test {
  [TestClass]
  public class BinaryHistoryPersistorTest {
    private BinaryHistoryPersistor m_Persistor;

    public BinaryHistoryPersistorTest() {
      BinaryFactory factory = new BinaryFactory();
      m_Persistor = new BinaryHistoryPersistor((IBinaryFactory<MonitoringCheck>)factory, (IBinaryFactory<RecordHeader>)factory, (IBinaryFactory<IndexEntry>)factory);
    }

    [TestMethod]
    public void TestSavingChecks() {
      Guid guid = Guid.NewGuid();
      MonitoringCheck check = new MonitoringCheck();
      check.CheckDate = new DateTime(1992, 1, 1);
      check.RequestLength = 2.1;
      check.StatusCode = 404;

      m_Persistor.SaveCheck(guid, check);
      check.RequestLength += 0.1;
      m_Persistor.SaveCheck(guid, check);
      check.RequestLength += 0.1;
      m_Persistor.SaveCheck(guid, check);
      check.RequestLength += 0.1;
      m_Persistor.SaveCheck(guid, check);

      int count = 0;
      foreach (MonitoringCheck boundCheck in m_Persistor.GetAllChecks(guid)) {
        Assert.AreEqual(boundCheck.StatusCode, check.StatusCode);
        Assert.AreEqual(boundCheck.CheckDate, check.CheckDate);
        count++;
      }

      Assert.AreEqual(count, 4);
    }
  }
}
